import { HttpService } from './../../services/http.service';
import { Component } from '@angular/core';
import { IonicPage, NavController, AlertController } from 'ionic-angular';


/**
 * Generated class for the StudyDemo page.
 *
 * See http://ionicframework.com/docs/components/#navigation for more info
 * on Ionic pages and navigation.
 */
@IonicPage()
@Component({
  selector: 'page-study-demo',
  templateUrl: 'study-demo.html',
})
export class StudyDemo {

  constructor(public navCtrl: NavController,
    public alertCtrl: AlertController,
    public httpservice: HttpService) {
  }

  presentAlert() {
    console.log("ni hao ");
    let alert = this.alertCtrl.create({
      title: 'Low battery',
      subTitle: '10% of battery remaining',
      buttons: ['Dismiss']
    });
    alert.present();
  }

  presentConfirm() {
    let alert = this.alertCtrl.create({
      title: 'Confirm purchase',
      message: 'Do you want to buy this book?',
      buttons: [
        {
          text: 'Cancel',
          role: 'cancel',
          handler: () => {
            console.log('Cancel clicked');
          }
        },
        {
          text: 'Buy',
          handler: () => {
            console.log('Buy clicked');
          }
        }
      ]
    });
    alert.present();
  }





  ionViewDidLoad() {
    console.log('ionViewDidLoad StudyDemo');

    this.httpservice.httpGetNoAuth("http://118.89.150.199:8080/api/notToken").then(p => {
      console.log(p);
      let alert = this.alertCtrl.create({
        title: 'Low battery',
        subTitle: p.message,
        buttons: ['OK']
      });
      alert.present();
    });
  }

}
